<?php
require_once '/home/qss/shupeng/dw/common/lib/ezcomponents/Base/src/ezc_bootstrap.php';
require_once '/home/qss/shupeng/dw/executor/workflow/variables/VariableHandler.php';
$workflow = new ezcWorkflow('DataXTransfer');

$setType = new ezcWorkflowNodeAction(array(
    'class' => 'TransferAction',
    'arguments' =>  array(
        'SetType',
    )
));

// Create a new Exclusive Choice node and add it as an
// outgoing node to the previously created Input node.
// This node will choose which output to run based on the
// choice workflow variable.
$branch = new ezcWorkflowNodeExclusiveChoice;

$createMysqlTable = new ezcWorkflowNodeAction(array(
    'class' => 'ActivityAction',
    'arguments' =>  array(
        'CreateMysqlTable',
    )
));

$hiveToMysql = new ezcWorkflowNodeAction(array(
    'class' => 'ActivityAction',
    'arguments' =>  array(
        'HiveToMysql',
    )
));


$hiveToRemoteFile = new ezcWorkflowNodeAction(array(
    'class' => 'ActivityAction',
    'arguments' =>  array(
        'HiveToRemoteFile',
    )
));

// Create SimpleMerge node and add the two possible threads of
// execution as incoming nodes of the end node.
$merge = new ezcWorkflowNodeSimpleMerge;


$workflow->startNode->addoutNode($setType);
$branch->addInNode($setType);

$branch->addConditionalOutNode(
    new ezcWorkflowConditionVariable('type', new ezcWorkflowConditionIsEqual(3)),
    $createMysqlTable
);

$branch->addConditionalOutNode(
    new ezcWorkflowConditionVariable('type', new ezcWorkflowConditionIsEqual(6)),
    $hiveToRemoteFile
);

$createMysqlTable->addOutNode($hiveToMysql);

$merge->addInNode($hiveToMysql);
$merge->addInNode($hiveToRemoteFile);
$merge->addOutNode($workflow->endNode);
$workflow->addVariableHandler('params', 'VariableHandler');
// Generate GraphViz/dot markup for workflow "Test".
//$visitor = new ezcWorkflowVisitorVisualization;
//$workflow->accept( $visitor );
//print $visitor;

// Set up database connection.
$db = ezcDbFactory::create( 'mysql://dw:dwcloud360@client05v.safe.zzbc.qihoo.net/dw' );

// Set up workflow definition storage (database).
$definition = new ezcWorkflowDatabaseDefinitionStorage( $db );

// Save workflow definition to database.
$definition->save( $workflow );

// Set up workflow definition storage (XML).
//$definition = new ezcWorkflowDefinitionStorageXml( './' );

// Save workflow definition to database.
//$definition->save( $workflow );
